package com.groupbuying.customer.controller;

import com.alipay.api.response.AlipayUserInfoShareResponse;
import com.groupbuying.customer.connector.SysconfigFeign;
import com.groupbuying.customer.constants.CustomerAlipayConstants;
import com.groupbuying.customer.domain.CustomerAliinfoRelDO;
import com.groupbuying.customer.service.CustomerAliinfoRelService;
import com.groupbuying.customer.utils.AliUntil;
import com.groupbuying.customer.utils.PageUtils;
import com.groupbuying.customer.utils.Query;
import com.groupbuying.customer.utils.R;
import com.groupbuying.customer.utils.apiresult.ApiResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 支付宝登录信息关联表
 *
 * @author gaoruijun
 * @email 18511893135@163.com
 * @date 2019-07-23 11:45:51
 */

@RestController
@RequestMapping("/customerAliinfoRel")
public class CustomerAliinfoRelController {
    @Autowired
    private CustomerAliinfoRelService customerAliinfoRelService;
    @Autowired
    private SysconfigFeign sysconfigFeign;

    /**
     * @api {post} /customerAliinfoRel/aliRegister 支付宝用户授权注册登录接口
     * @apiExample
     * author yangmeng
     * tar 用于客户端小程序调用
     * date 2019/10/31 14:11
     * @apiGroup bus-customer
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} authCode 支付宝用户授权code
     * @apiSuccess {ApiResult} success 登录成功
     * @apiSuccess {ApiResult} failure 请求access_token失败
     */
    @PostMapping("/aliRegister")
    public ApiResult aliRegister(@RequestParam("authCode") String authCode) {
        return customerAliinfoRelService.customerAliRegister(authCode);
    }

    /**
     * @api {get} /customerAliinfoRel/getAliUserId 根据customerId获取aliuserId
     * @apiExample
     * author yangmeng
     * tar 用于api内部调用
     * date 2019/10/31 14:13
     * @apiGroup bus-customer
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} customerId 会员ID
     * @apiSuccess {String} aliUserId 支付宝用户userId
     */
    @GetMapping("/getAliUserId")
    public String getAliUserId(@RequestParam("customerId") String customerId) {
        return customerAliinfoRelService.getAliUserIdByCustomerId(customerId);
    }

    /**
     * @api {post} /customerAliinfoRel/regiestForAli 支付宝用户手机号授权注册登录接口
     * @apiExample
     * author yangmeng
     * tar 用于客户端小程序调用
     * date 2019/10/31 14:15
     * @apiGroup bus-customer
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} authcode 支付宝用户授权code
     * @apiParam {String} encryptedData 支付宝用户授权手机号加密信息
     * @apiSuccess {ApiResult} success 登录成功
     * @apiSuccess {ApiResult} failure 请求access_token失败
     */
    @PostMapping("/regiestForAli")
    public ApiResult regiestForAli(@RequestParam Map<String,String> param) {
        return customerAliinfoRelService.regiestForAli( param);
    }
}
